//
//  WATFHomeBottomView.swift
//  WiFiFaster
//
//  Created by one on 2023/12/28.
//

import UIKit

class WATFHomeBottomView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(watf_bgView)
        addSubview(watf_upView)
        addSubview(watf_speedView)
        addSubview(watf_ftvButton)
        addSubview(watf_tipView)
        watf_bgView.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.centerX.top.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        watf_ftvButton.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 194, height: 54))
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(70)
        }
        watf_upView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 154, height: 58))
            make.top.equalTo(watf_ftvButton.snp.bottom).offset(32)
            make.right.equalTo(self.snp.centerX).offset(-6)
        }
        watf_speedView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 154, height: 58))
            make.top.equalTo(watf_ftvButton.snp.bottom).offset(32)
            make.left.equalTo(self.snp.centerX).offset(6)
        }
        watf_tipView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 64, height: 66))
            make.centerX.equalTo(watf_ftvButton.snp.right)
            make.top.equalTo(watf_ftvButton.snp.top).offset(18)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - watf action
    
    @objc func watf_speedClick() {
        watf_upView.setBackgroundImage(UIImage(named: "watf_home_unselect"), for: .normal)
        watf_speedView.setBackgroundImage(UIImage(named: "watf_home_select"), for: .normal)
        (watf_viewGetVController as? WATFBaseViewController)?.watf_funcClickModel(watf_funcModel: watf_speedModel)
    }
    @objc func watf_speedUpClick() {
        watf_speedView.setBackgroundImage(UIImage(named: "watf_home_unselect"), for: .normal)
        watf_upView.setBackgroundImage(UIImage(named: "watf_home_select"), for: .normal)
        (watf_viewGetVController as? WATFBaseViewController)?.watf_funcClickModel(watf_funcModel: watf_upModel)
    }
    @objc func watf_ftvStateView() {
        
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_connected && !WATFManager.watf_manager.watf_ftvWork{
            watf_ftvButton.setTitle("Connected", for: .normal)
            watf_upView.isHidden = false
            watf_speedView.isHidden = false
            watf_ftvButton.isUserInteractionEnabled = true
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_connecting {
            watf_ftvButton.setTitle("Connecting", for: .normal)
            watf_ftvButton.isUserInteractionEnabled = false
//           6edView.isHidden = false
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_disconnecting {
            watf_ftvButton.setTitle("DisConnecting", for: .normal)
            watf_ftvButton.isUserInteractionEnabled = false
            watf_upView.isHidden = false
            watf_speedView.isHidden = false
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_disconnected && !WATFManager.watf_manager.watf_ftvWork{
            watf_ftvButton.setTitle("Connect", for: .normal)
            watf_ftvButton.isUserInteractionEnabled = true
            watf_upView.isHidden = true
            watf_speedView.isHidden = true
            
        }
        if WATFManager.watf_manager.watf_ftvCurStateType == .watf_invalid {
            watf_ftvButton.setTitle("Connect", for: .normal)
            watf_upView.isHidden = true
            watf_speedView.isHidden = true
        }
    }
    // MARK: - watf lazy
    var watf_speedModel = WATFManager.watf_manager.watf_funcModels.first
    var watf_upModel = WATFManager.watf_manager.watf_funcModels.first { watf_funcModel in
        return watf_funcModel.watf_type == .watf_speedUP
    }
    lazy var watf_bgView: UIImageView = {
        let watf_bgView = UIImageView(image: UIImage(named: "watf_home_bottomBg")?.resizableImage(withCapInsets: UIEdgeInsets(top: 100, left: 20, bottom: 20, right: 100), resizingMode: .stretch))
        return watf_bgView
    }()
    lazy var watf_ftvButton: UIButton = {
        let watf_ftvButton = UIButton()
        watf_ftvButton.setBackgroundImage(UIImage(named: "watf_ftv_stateBg"), for: .normal)
        watf_ftvButton.setTitleColor(.white, for: .normal)
        watf_ftvButton.titleLabel?.font = UIFont.systemFont(ofSize: 20)
        watf_ftvButton.setTitle("Connect", for: .normal)
        return watf_ftvButton
    }()
    lazy var watf_upView: UIButton = {
        let watf_upView = UIButton()
        watf_upView.setBackgroundImage(UIImage(named: "watf_home_unselect"), for: .normal)
        watf_upView.setTitle("Speed up", for: .normal)
        watf_upView.setTitleColor(.white, for: .normal)
        watf_upView.titleLabel?.font = UIFont.systemFont(ofSize: 20)
        watf_upView.addTarget(self, action: #selector(watf_speedUpClick), for: .touchUpInside)
        watf_upView.isHidden = true
        return watf_upView
    }()
    lazy var watf_speedView: UIButton = {
        let watf_speedView = UIButton()
        watf_speedView.setBackgroundImage(UIImage(named: "watf_home_unselect"), for: .normal)
        watf_speedView.setTitle("Test speed", for: .normal)
        watf_speedView.setTitleColor(.white, for: .normal)
        watf_speedView.titleLabel?.font = UIFont.systemFont(ofSize: 20)
        watf_speedView.addTarget(self, action: #selector(watf_speedClick), for: .touchUpInside)
        watf_speedView.isHidden = true
        return watf_speedView
    }()
    lazy var watf_tipView: UIImageView = {
        let watf_tipView = UIImageView(image: UIImage(named: "watf_ftv_tip"))
        return watf_tipView
    }()
    
}

